﻿using StockModel;
using TechnicalIndicators.Points;
using Utils;

namespace TechnicalIndicators.QuotationBased
{
	public class OpenPercentageGenerator : GeneratorBase<Quotation, DatedSeriePoint>
	{
		#region Attributes

		private decimal _openValue;

		#endregion

		#region Public Methods

		public OpenPercentageGenerator(ObservableCollection2<DatedSeriePoint> destination) : base(destination)
		{
			_openValue = 0.0m;
		}

		protected override DatedSeriePoint CreatePoint(Quotation quotation)
		{
			if (quotation.Volume == 0)
			{
				return null;
			}
			else
			{
				if (_openValue == 0.0m)
				{
					_openValue = quotation.Value;
				}

				return new DatedSeriePoint(quotation.Date, quotation.Value * 100 / _openValue - 100);
			}
		}

		public override void Clear()
		{
			_openValue = 0.0m;

			base.Clear();
		}

		#endregion
	}
}
